// pages/detail/detail.ts
import { getProDetail } from '../../api/detail'
import { IResData } from '../home/type'
Page({
  data: {
    // 产品的 ID 
    proid: '',
    // 产品的轮播广告图
    banners: [],
    // 产品的名字
    proname: '',
    // 产品的价格
    originprice: 0,
    // 轮播器的索引
    current: 0
  },
  // 接收路由传递的参数，在 onLoad 里面直接可以拿到
  onLoad(options: { proid: string }) {
    console.log(options)
    const proid = options.proid
    getProDetail(proid).then(res => {
      // console.log((res as IResData).data.data)
      const result = (res as IResData).data.data
      const banners = result.banners
      this.setData({
        proid,
        banners: banners[0].split(','),
        proname: result.proname,
        originprice: result.originprice
      })
    })
  },
  changeSwiper(event: { detail: { current: number } }) {
    this.setData({
      current: event.detail.current
    })
  },
  previewImage() {
    console.log(this.data.banners);
    
    wx.previewImage({
      urls: this.data.banners,
      current: this.data.banners[this.data.current]
    })
  }
})